package mvc.model;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Alfabeto {
	
	private static final List<Character> alfabeto = new ArrayList<Character>();
	private static List<Boolean> alfabetoFlag = new ArrayList<Boolean>();
	
	public Alfabeto() {
		Character letra;
		for (int i = 97 ; i < 123 ; i++) {
			letra = (char)i;
			alfabeto.add(Character.toUpperCase(letra.charValue()));
			alfabetoFlag.add(true);
		}
	}
	

	
	public String getAlfabeto(){
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < alfabeto.size(); i++) {
			if (alfabetoFlag.get(i).booleanValue()){
				sb.append(alfabeto.get(i).charValue()+" ");
			}
		}
		return sb.toString();
	}
	
	public boolean validaLetraAlfabeto(char caractere){
		Character letraInformada = new Character(caractere);
		letraInformada = Character.toUpperCase(letraInformada.charValue());
		for (Character letraAlfabeto : alfabeto) {
			if (letraAlfabeto.equals(letraInformada)){
				return true;
			}
		}
		return false;
	}
	
	public boolean validaFlagAlfabeto(char caractere){
		Character letraInformada = new Character(caractere);
		letraInformada = Character.toUpperCase(letraInformada.charValue());
		int indice = alfabeto.indexOf(letraInformada);
		if (alfabetoFlag.get(indice).booleanValue()){
				alfabetoFlag.set(alfabeto.indexOf(letraInformada), false);
				return true;
		}
		return false;
	}
	public char getUserInputChar (String prompt){
        String inputline = null;
        char c = ' ';
        System.out.println(prompt + " ");
        
        try{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 
        inputline=in.readLine().toUpperCase();
        
        if(inputline.length() == 0){
                System.out.println("Erro na entrada!!!");                       
        }
         c = trataLetras(inputline);
             
        
        }catch(IOException ex){
                System.out.println("IOException: " + ex);
        }
        return c;
    }
    
    public char trataLetras(String letra){
            String valor = letra;
            char s;
            
            valor = valor.replaceAll("[èéêë]","e");
            valor = valor.replaceAll("[ûù]","u");
            valor = valor.replaceAll("[ïî]","i");
            valor = valor.replaceAll("[àâ]","a");
            valor = valor.replaceAll("Ô","o");
            valor = valor.replaceAll("[çÇ]", "c");
            
            valor = valor.replaceAll("[ÈÉÊË]","E");
            valor = valor.replaceAll("[ÛÙ]","U");
            valor = valor.replaceAll("[ÏÎ]","I");
            valor = valor.replaceAll("[ÀÂ]","A");
            valor = valor.replaceAll("Ô","O");
            
            s = valor.charAt(0);
            return s;
    }
	
}
